<?php
session_start();
if (isset($_SESSION['userid']) && $_SESSION['level']!=2)
{
	header ("location: login.php");
	exit();
}

?>
<?php
include("includes/top_user.php");
?>
<?php
include("includes/connect.php");
$id=$_GET['cateid'];
$sql="select id,cate_name,category.maloai, tenloai
	  from category, type_category
	  where category.maloai = type_category.maloai
	  and id='".$id."' ";
mysql_query("set names 'utf8'");
$query=mysql_query($sql);
$row=mysql_fetch_array($query);
if(isset($_POST['ok']))
{
	
	if($_POST['tb_id'] == "") { echo "Please enter your category id"; }
	else{ $t = $_POST['tb_id']; }
	if($_POST['tb_cate_name'] == "") { echo "Please enter your cate name"; }
	else{ $c = $_POST['tb_cate_name']; }
	$maloai = $_POST['maloai'];
	
	if($t!="" && $c!="" && $maloai!=="")
	{
		$sql = "update category set id='".$t."', cate_name='".$c."', maloai='".$maloai."' where id='".$id."'";
		mysql_query($sql);
		header("location: main_manager.php");
		exit();
 	}
}

?>
<div id="box">
<h3>Quản lý danh mục</h3>
<form class="fr_manage_type" name="fr_manage_type" action="edit_cate.php?cateid=<?=$id?>" method="post">
    
    Mã Danh Mục : <input type="text" name="tb_id" size="20" value="<?=$row['id']?>"  /> <br />
    Tên Danh Mục : <input type="text" name="tb_cate_name"  value="<?=$row['cate_name']?>"  /> <br />
    Thuộc Thể Loại : <select name="maloai">
    				<?php
					
					$sql_type = "select * from type_category";
					$query_type = mysql_query($sql_type);
					while($row_type = mysql_fetch_array($query_type))
					{
						if($row_type['maloai']==$row['maloai'])
						{
							echo "<option value=$row_type[maloai] selected >$row_type[tenloai]</option>";
						}
						else
						{
								echo "<option value=$row_type[maloai]>$row_type[tenloai]</option>";
						}
					}
					?>
    				</select><br />
    <input type="submit" name="ok" value="Cập Nhật"  />
        
</form>
</div>
<?
include("includes/sidebar.php");
include("includes/footer.php");
?>